package generic.method;

import java.util.function.Supplier;
import java.util.stream.Stream;

public class BasicSupplier<T> implements Supplier<T> {
    private Class<T> type;

    public BasicSupplier(Class<T> type) {
        this.type = type;
    }
    @Override
    public T get() {
        try {
            return type.newInstance();
        } catch (InstantiationException|IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
    public static <T> Supplier<T> create(Class<T> type) {
        return new BasicSupplier<>(type);
    }

    public static void main(String[] args) {
        Stream.generate(BasicSupplier.create(People.class))
                .limit(50)
                .forEach(System.out::println);
    }
}
class People {
    private static int p = 0;
    private final int id = p++;

    @Override
    public String toString() {
        return this.getClass().getSimpleName() + " " + id;
    }
}